deltas: Handle cleanup of fd array properly
authorDan Nicholson <nicholson@endlessm.com>
Tue, 9 Aug 2016 18:45:25 +0000 (11:45 -0700)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 10 Aug 2016 10:54:46 +0000 (10:54 +0000)
If there's an early error, part_temp_fds will be NULL and dereferencing
the len member will segfault.

Closes: #454
Closes: #448
Approved by: cgwalters

src/libostree/ostree-repo-static-delta-compilation.c

index 8b3880940f58e8da103a90cf11264ca673584eb0..7ef7680dc50ec8c6d5e5e3def0144d43bb6f34f1 100644 (file)
@@ -1584,13 +1584,14 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
 
   ret = TRUE;
  out:
-  for (i = 0; i < part_temp_fds->len; i++)
-    {
-      int fd = g_array_index (part_temp_fds, int, i);
-      if (fd == -1)
-        continue;
-      (void) close (fd);
-    }
+  if (part_temp_fds)
+    for (i = 0; i < part_temp_fds->len; i++)
+      {
+        int fd = g_array_index (part_temp_fds, int, i);
+        if (fd == -1)
+          continue;
+        (void) close (fd);
+      }
   g_clear_pointer (&builder.parts, g_ptr_array_unref);
   g_clear_pointer (&builder.fallback_objects, g_ptr_array_unref);
   return ret;